import { Alert, Button, Result } from "antd";
import React from "react";
import { MicroAppContext } from "..";
export default class ErrorBoundary extends React.Component<any, any> {
    unListen: (() => void) | undefined;
    static contextType?: React.Context<any> = MicroAppContext;
    constructor(props: any) {
        super(props);
        this.state = {
            hasError: false,
            message: '',
            stack: ''
        };

    }
    componentDidMount(): void {
        // this.unlisten = history.listen(() => {
        //     debug('路由改变')
        //     this.setState({
        //         hasError: false,
        // })
    }
    componentWillUnmount(): void {
        if (this.unListen) {
            this.unListen()
        }
    }

    componentDidCatch(error: Error, errorInfo: React.ErrorInfo): void {
        // debug({ error })
        this.setState({
            hasError: true,
            message: error.message,
            stack: error.stack
        })
    }
    render() {

        if (this.state.hasError) {

            // 你可以自定义降级后的 UI 并渲染
            return (
                <div>页面渲染错误</div>
            );
        }

        return this.props.children;
    }

}